package com.ctvit.sms.platform.service;


import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;

import com.ctvit.common.FilerollService;
import com.ctvit.framework.dao.Condition;
import com.ctvit.framework.service.BaseService;
import com.ctvit.sms.platform.domain.SystemConfig;
import com.ctvit.struts.common.CommonFunc;
import com.ctvit.syn.service.SynchronizeDataService;

public class FileTaskService extends BaseService{
	private FilerollService filerollService;
	private SynchronizeDataService synService;
	
	public void checkNewFileTask()throws Exception{
		try {
//			if (StringUtils.equals(CommonFunc.fileTaskTime, "local")){
//				filerollService.doGetFiles(CommonFunc.remoteFileDir);
//				log.info("begin scan for instock and live msg");
//				msgService.doScanMsg();
//				log.info("begin create oa notice msg");
//				msgService.doGeneNotice();
//				synService.synchronizeData();
//			}else if (StringUtils.equals(CommonFunc.fileTaskTime, "remote")){
////				log.info("begin check qualified send task");
////				msgService.doExecSendMsg("'1','2'","");
//			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void startTimer(){
		Condition condition=new Condition();int intervalSec=120;//默认检查间隔120秒
		if (CommonFunc.intervalSec==0){
			condition.add("zCfgId", "CHECKINTERVAL");//秒数
			SystemConfig sConfig=(SystemConfig)genericDao.getObjectByCondition(SystemConfig.class, condition);
			if (sConfig!=null){
				intervalSec=Integer.parseInt(sConfig.getZCfgVal());
			}
			CommonFunc.intervalSec=intervalSec;
		}else{
			intervalSec=CommonFunc.intervalSec;
		}
		ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
		executorService.scheduleAtFixedRate(new Runnable() {  
            @Override  
            public void run() {  
                try {  
                	checkNewFileTask();
                    } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }  
        }, 0, intervalSec, TimeUnit.SECONDS); 
	}
	public FilerollService getFilerollService() {
		return filerollService;
	}
	public void setFilerollService(FilerollService filerollService) {
		this.filerollService = filerollService;
	}
	public SynchronizeDataService getSynService() {
		return synService;
	}
	public void setSynService(SynchronizeDataService synService) {
		this.synService = synService;
	}

}
